from app import ma
from .models import Tag

class TagSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Tag
        load_instance = True
        fields = ('id', 'name', 'recipes')
    
    # 【关键修复】跨模块嵌套用字符串引用，不使用exclude因为RecipeSimpleSchema中没有tags字段
    recipes = ma.Nested('app.recipes.schemas.RecipeSimpleSchema', many=True)

tag_schema = TagSchema()
tags_schema = TagSchema(many=True)